<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class giaovien_db 
	{
		public function Them($MaGiaoVien, $MaChucVu, $HoTen, $NgaySinh, $GioiTinh, $DiaChi, $DienThoai, $Email, $MatKhau, $PIN)
		{
			$sql = "INSERT INTO `tbl_giaovien`(`MaGiaoVien`, `MaChucVu`, `HoTen`, `NgaySinh`, `GioiTinh`, `DiaChi`, `DienThoai`, `Email`, `MatKhau`, `PIN`)
					VALUES ('$MaGiaoVien', '$MaChucVu', '$HoTen', '$NgaySinh', '$GioiTinh', '$DiaChi', '$DienThoai', '$Email', '$MatKhau', '$PIN')";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($MaGiaoVien)
		{
			$sql = "DELETE FROM `tbl_giaovien` WHERE `MaGiaoVien` = '$MaGiaoVien'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($MaGiaoVien, $MaChucVu, $HoTen, $NgaySinh, $GioiTinh, $DiaChi, $DienThoai, $Email, $MatKhau, $PIN)
		{
			$sql = "UPDATE `tbl_giaovien`
					SET `MaChucVu` = '$MaChucVu', `HoTen` = '$HoTen', `NgaySinh` = '$NgaySinh', `GioiTinh` = '$GioiTinh', `DiaChi` = '$DiaChi', `DienThoai` = '$DienThoai', `Email` = '$Email', `MatKhau` = '$MatKhau', `PIN` = '$PIN'
					WHERE `MaGiaoVien` = '$MaGiaoVien'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($MaGiaoVien, $MaChucVu, $HoTen, $NgaySinh, $GioiTinh, $DiaChi, $DienThoai, $Email, $MatKhau, $PIN)
		{
			$sql = "SELECT * FROM `tbl_giaovien` WHERE 1  ";
			if($MaGiaoVien != "")
				$sql .= " AND `MaGiaoVien` = '$MaGiaoVien' ";

			if($MaChucVu != "")
				$sql .= " AND `MaChucVu` = '$MaChucVu' ";

			if($HoTen != "")
				$sql .= " AND `HoTen` = '$HoTen' ";

			if($NgaySinh != "0000-00-00")
				$sql .= " AND `NgaySinh` = '$NgaySinh' ";

			if($GioiTinh != -1)
				$sql .= " AND `GioiTinh` = '$GioiTinh' ";

			if($DiaChi != "")
				$sql .= " AND `DiaChi` = '$DiaChi' ";

			if($DienThoai != "")
				$sql .= " AND `DienThoai` = '$DienThoai' ";

			if($Email != "")
				$sql .= " AND `Email` = '$Email' ";

			if($MatKhau != "")
				$sql .= " AND `MatKhau` = '$MatKhau' ";

			if($PIN != "")
				$sql .= " AND `PIN` = '$PIN' ";

			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

